package com.ruoyi.common.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class OrderCodeUtils {

    public static String getOrderCode(String prefix) {
        // 1. 大写字母S
//        String prefix = "S";

        // 2. 14位时间戳 (格式: yyyyMMddHHmmss)
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        String timestamp = now.format(formatter);

        // 3. 3位随机数
        Random random = new Random();
        int randomNum = random.nextInt(900) + 100; // 保证是3位数(100-999)

        return prefix + timestamp + randomNum;
    }

}
